<!DOCTYPE html>
<html>
<head>
	<title>登录/注册</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=no, maximum-scale=1.0"/>
	<meta content="yes" name="apple-mobile-web-app-capable" />
	<meta content="black" name="apple-mobile-web-app-status-bar-style" />
	<meta content="telephone=no" name="format-detection" />
	<link href="{G_TEMPLATES_CSS}/wx/login.css" rel="stylesheet">
	<link href="{G_TEMPLATES_CSS}/wx/comm.css" rel="stylesheet">
	<script src="{G_TEMPLATES_JS}/wx/jquery-2.1.4.min.js"></script>
	<script src="{G_TEMPLATES_JS}/wx/pageDialog.js"></script> 
  <style>
       body{
          background-color:#F3F3F3;
      }
  </style>
	
</head>
<body>
	{wc:templates "mobile/index","header"}

	<div class="main">
		<ul>
			<li><span class="main-fl">注册</span></li>
			<li><span class="main-fl select">登录</span></li>
		</ul>
		<div class="clear"></div>
	</div>

	<div class="register page">
		<form action="" method="post">
			<ul>
				<li>
					<input type="text" class="input user-phone" value="" placeholder="请输入手机号码">
					<span class="register-error">
						<span class="send-yzm" state="0">获取验证码</span>
						<img src="{G_TEMPLATES_IMAGE}/wx/error.png" class="error-img">
					</span>
				</li>
				<li>
					<input type="text" class="input yzm" id="yzm" value="" placeholder="请输入验证码">
					<span class="register-error"><img src="{G_TEMPLATES_IMAGE}/wx/error.png" class="error-img"></span>
				</li>
				<li>
					<input type="password" class="input user-psw" value="" placeholder="请输入6-18位密码">
					<span class="register-error">
						<img src="{G_TEMPLATES_IMAGE}/wx/look.png" class="look-img" state="0">
						<img src="{G_TEMPLATES_IMAGE}/wx/error.png" class="error-img">
					</span>
				</li>
			</ul>
			<div class="protocol">
				<input type="checkbox" class="read-check" onclick='ClickBigCheckBox()' state="0">
				<span class="protocol-font">已同意用户协议</span>
			</div>
			<input type="button" class="register-btn btn-forbid" value="注册" disabled="true">
		</form>
	</div>

	<div class="login page">
		<form action="" method="post">
			<ul>
				<li>
					<input type="text" class="input user-phone" value="" placeholder="请输入手机号码">
					<span class="error"><img src="{G_TEMPLATES_IMAGE}/wx/error.png" class="error-img"></span>
				</li>
				<li>
					<input type="password" class="input user-psw" value="" placeholder="请输入6-18位密码">
					<span class="error">
						<img src="{G_TEMPLATES_IMAGE}/wx/look.png" class="look-img">
						<img src="{G_TEMPLATES_IMAGE}/wx/error.png" class="error-img">
					</span>
				</li>
			</ul>
			<div class="find-psw">忘记密码？</div>
			<input type="button" class="login-btn" value="登录">

		</form>
		 <!----<div class="login-fast">
         	<div class="hr2"></div>
            <div class="login-fast-font">一键登录</div>
            <div class="hr3"></div>
       	 </div>
                
         <a style="color: green" href="{WEB_PATH}/mobile/user/wxlogin">
         	<img src="{G_TEMPLATES_IMAGE}/wx/wx-ico.png" class="fast-wx">
         </a>--->
         </div>
	</div>
	{wc:templates "mobile/index","footer"}
	<script>
		$(document).ready(function(e) {
			$(".user-phone").focus();
			$(".main ul li").click(function(){
				$(".main-fl").removeClass("select");
				var sw=$(".main ul li").index(this);
				$(".main ul li").eq(sw).children("span").addClass("select");
				$(".page").eq(sw).show().siblings(".page").hide();
				$(".page:eq("+sw+") .user-phone").focus();
			})
			$(".look-img").click(function(){
				var sw=$(".look-img").index(this);
				var sta=$(".look-img").attr("state");
				if(sta==0){
					$(".user-psw").attr("type","text");
					$(".look-img").attr("state","1");
				}else{
					$(".user-psw").attr("type","password");
					$(".look-img").attr("state","0");
				}
			})
			$(".error-img").click(function(){
				var sw=$(".error-img").index(this);
				$(".input").eq(sw).val("");
				$(".input").eq(sw).focus();
			})
			$(".send-yzm").click(function(){
				var sta=$(".send-yzm").attr("state");
				if(sta==0){
					var myreg =/^1\d{10}$/;
					var val=$(".register .user-phone").val();
					var phone= val;
					if(!myreg.test(val)){
						alert("请输入正确手机号！");
					}else{
						$.post("{WEB_PATH}/mobile/user/adduser/",{phone:phone},function(data){
							var ret = JSON.parse(data);
							var t = ret.msg;
							if(ret.sta==1){

								$.PageDialog.fail(t);
								timer();
								return false ;
							}else {
								$.PageDialog.fail(t);
								return false;
							}
						});
					}
				}else{

				}
			})
			$(".login-btn").click(function(){
				var myreg =/^1\d{10}$/;
				var pswreg=/^\S{6,18}$/;
				var val=$(".login .user-phone").val();
				var psw=$(".login .user-psw").val();
				var phone = val;

				var password = base64encode(utf16to8(psw));

				if(!myreg.test(val)){
					alert("请输入正确手机号！");
				}else{
					if(!pswreg.test(psw)){
						alert("请输入6-18位的密码")
					}else{
						
						$.post("{WEB_PATH}/mobile/user/userlogins/",{phone:phone,password:password},function(data){
							var ret = JSON.parse(data);
							
							if(ret.sta == 1){
								$.PageDialog.fail(ret.msg);
								/* 延迟3秒钟，进入登录页面*/
								setInterval(function(){
									window.location.href="{WEB_PATH}/mobile/home";
								},3000);
								return false;
							}else{
								$.PageDialog.fail(ret.msg);
								return false;
							}
						});
						
					}
				}
			})
			$(".register-btn").click(function(){
				var myreg =/^1\d{10}$/;
				var pswreg=/^\S{6,18}$/;
				var val=$(".register .user-phone").val();
				var psw=$(".register .user-psw").val();
				var yzm=$(".yzm").val();
				var phone = val;
				var password = psw;
				var randcode = yzm;
				if(!myreg.test(val)){
					alert("请输入正确手机号！");
				}else{
					if(!pswreg.test(psw)){
						alert("请输入6-18位的密码")
					}else{

						$.post("{WEB_PATH}/mobile/user/updateusers/",{phone:phone,password:password,randcode:randcode},function(data){
							var ret = JSON.parse(data);
							
							if(ret.sta == 1){
								$.PageDialog.fail(ret.msg);
								/* 延迟3秒钟，进入登录页面*/
								setInterval(function(){
									window.location.href="{WEB_PATH}/mobile/user/login";
								},3000);
								return false;
							}else{
								$.PageDialog.fail(ret.msg);
								return false;
							}
						});
					}
				}
			})
			function timer(){
				var tm=60;
				$(".send-yzm").attr("state","1")
				var t=setInterval(function(){
					tm--;
					if(tm<1){
						clearInterval(t);
						$(".send-yzm").text("重新发送");
						$(".send-yzm").attr("state","0")
					}else{
						$(".send-yzm").text(tm);
					}
				},1000)
			}
		});
	</script>
	<!--注册按钮-->
	<script>
		function ClickBigCheckBox(){
			var sta=$(".read-check").attr("state");
			if(sta==0){
				$(".register-btn").removeClass("btn-forbid");
				$(".register-btn").removeAttr("disabled");
				$(".read-check").attr("state","1");
			}else{
				$(".register-btn").addClass("btn-forbid");
				$(".register-btn").attr("disabled","true");
				$(".read-check").attr("state","0");
			}
		}


	</script>

	<script type="text/javascript">
		var base64encodechars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
		var base64decodechars = new Array(
			-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
			-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
			-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
			52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
			-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
			15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
			-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
			41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
		function base64encode(str) {
			var out, i, len;
			var c1, c2, c3;
			len = str.length;
			i = 0;
			out = "";
			while (i < len) {
				c1 = str.charCodeAt(i++) & 0xff;
				if (i == len) {
					out += base64encodechars.charAt(c1 >> 2);
					out += base64encodechars.charAt((c1 & 0x3) << 4);
					out += "==";
					break;
				}
				c2 = str.charCodeAt(i++);
				if (i == len) {
					out += base64encodechars.charAt(c1 >> 2);
					out += base64encodechars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4));
					out += base64encodechars.charAt((c2 & 0xf) << 2);
					out += "=";
					break;
				}
				c3 = str.charCodeAt(i++);
				out += base64encodechars.charAt(c1 >> 2);
				out += base64encodechars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4));
				out += base64encodechars.charAt(((c2 & 0xf) << 2) | ((c3 & 0xc0) >> 6));
				out += base64encodechars.charAt(c3 & 0x3f);
			}
			return out;
		}
		function base64decode(str) {
			var c1, c2, c3, c4;
			var i, len, out;
			len = str.length;
			i = 0;
			out = "";
			while (i < len) {

				do {
					c1 = base64decodechars[str.charCodeAt(i++) & 0xff];
				} while (i < len && c1 == -1);
				if (c1 == -1)
					break;

				do {
					c2 = base64decodechars[str.charCodeAt(i++) & 0xff];
				} while (i < len && c2 == -1);
				if (c2 == -1)
					break;
				out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));

				do {
					c3 = str.charCodeAt(i++) & 0xff;
					if (c3 == 61)
						return out;
					c3 = base64decodechars[c3];
				} while (i < len && c3 == -1);
				if (c3 == -1)
					break;
				out += String.fromCharCode(((c2 & 0xf) << 4) | ((c3 & 0x3c) >> 2));

				do {
					c4 = str.charCodeAt(i++) & 0xff;
					if (c4 == 61)
						return out;
					c4 = base64decodechars[c4];
				} while (i < len && c4 == -1);
				if (c4 == -1)
					break;
				out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
			}
			return out;
		}
		function utf16to8(str) {
			var out, i, len, c;
			out = "";
			len = str.length;
			for (i = 0; i < len; i++) {
				c = str.charCodeAt(i);
				if ((c >= 0x0001) && (c <= 0x007f)) {
					out += str.charAt(i);
				} else if (c > 0x07ff) {
					out += String.fromCharCode(0xe0 | ((c >> 12) & 0x0f));
					out += String.fromCharCode(0x80 | ((c >> 6) & 0x3f));
					out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f));
				} else {
					out += String.fromCharCode(0xc0 | ((c >> 6) & 0x1f));

					out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f));
				}
			}
			return out;
		}
		function utf8to16(str) {
			var out, i, len, c;
			var char2, char3;
			out = "";
			len = str.length;
			i = 0;
			while (i < len) {
				c = str.charCodeAt(i++);
				switch (c >> 4) {
					case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
            // 0xxxxxxx
            out += str.charAt(i - 1);
            break;
            case 12: case 13:
            // 110x xxxx   10xx xxxx
            char2 = str.charCodeAt(i++);
            out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f));
            break;
            case 14:
            // 1110 xxxx  10xx xxxx  10xx xxxx
            char2 = str.charCodeAt(i++);
            char3 = str.charCodeAt(i++);
            out += String.fromCharCode(((c & 0x0f) << 12) |
            	((char2 & 0x3f) << 6) |
            	((char3 & 0x3f) << 0));
            break;
        }
    }
    return out;
}
</script>

</body>
</html>
